import store from '@/store'
// import router from '@/router'
import axios from 'axios'
const request = axios.create({
    baseURL: 'http://hmmm-api.itheima.net/', // 接口的基准路径
    // transformResponse: [function(data) {
    //     try {
    //         return JSONBig.parse(data)
    //     } catch (err) {
    //         return data
    //     }
    //     // axios 默认会在内部这样来处理后端返回的数据
    //     // return JSON.parse(data)
    // }]
})
request.interceptors.request.use(config => {
    // Do something before request is sent
    const {
        user
    } = store.state
    // console.log(user)
    if (user && user.token) {
        config.headers.Authorization = `Bearer ${user.token}`
    }
    return config
}, error => {
    // Do something with request error
    return Promise.reject(error)
})

export default request